<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>节流</title>
  <style>
    #container {
      width: 100%;
      height: 200px;
      line-height: 200px;
      text-align: center;
      color: #fff;
      background-color: #444;
      font-size: 30px;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <script>
    let count = 1
    const container = document.getElementById('container')

    function getUserAction(e) {
      console.log(this)
      console.log(e)
      container.innerHTML = count++
    }

    function throttle(func, wait) {
      let canRun = true
      return function () {
        if (!canRun) return
        const context = this
        const args = arguments
        canRun = false
        setTimeout(function () {
          func.apply(context, args)
          canRun = true
        }, wait)
      }
    }

    container.onmousemove = throttle(getUserAction, 3000)
    // container.onmousemove = getUserAction
  </script>
</body>

</html>